<!DOCTYPE html>
<html class="x-admin-sm">
<head>
	<meta charset="UTF-8">
	<title>电子学会比赛管理系统</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
	<link rel="stylesheet" href="./css/font.css">
	<link rel="stylesheet" href="./css/xadmin.css">
	<script type="text/javascript" src="./js/abkj/oss/app.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/banner.js"></script>
	<script type="text/javascript" src="./js/abkj/fun_tool.js"></script>
	<script type="text/javascript" src="./js/abkj/slAjax.js"></script>
	<!-- 引入在线资源 -->
	<script src="http://gosspublic.alicdn.com/aliyun-oss-sdk-6.4.0.min.js"></script>
	<script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
	<script type="text/javascript" src="./js/xadmin.js"></script>
	<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
	<!--[if lt IE 9]>
	<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
	<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
	<![endif]--></head>

<body>
<div class="layui-fluid">
	<div class="layui-row">
		<div class="layui-input-inline">
			<button type="button" id="test1"
							style="width: 80px;height: 80px;background: #ffffff;border: 1px solid #999;border: 1px dashed #d9d9d9;background-color: #fafafa;">
				<i class="layui-icon layui-icon-add-1" style="font-size: 30px;"></i>
				<section>
					上传图片
				</section>
			</button>
			<div class="layui-upload-list">
				<section id="demo1" class="img" style="width: 270px; height: 150px;display: none; background-size: cover;"></section>
			</div>
			<section class="tips x-red">（支持PNG、JPG、PEG 格式，图片大小1920*520）</section>
		</div>
		<table style="display: none">
            <tr>
                <td>
                    <div class="panel panel-primary">
                        <div class="panel-heading">Upload file</div>
                        <div class="panel-body">
                            <form action="" class="form-horizontal">
                                <div class="form-group">
                                    <label>Select file</label>
                                    <input type="file" id="file" />
                                </div>
                                <div class="form-group">
                                    <label>Store as</label>
                                    <input type="text" class="form-control" id="object-key-file" value="object" />
                                </div>
                                <div class="form-group">
                                    <input type="button" class="btn btn-primary" id="file-button" value="Upload" />
                                </div>
                            </form>
                            <br />
                            <div class="progress">
                                <div id="progress-bar"
                                     class="progress-bar"
                                     role="progressbar"
                                     aria-valuenow="0"
                                     aria-valuemin="0"
                                     aria-valuemax="100" style="min-width: 2em;">
                                    0%
                                </div>
                            </div>
                        </div>
                    </div>
                </td>

            </tr>
        </table>
		<!-- <div class="layui-upload" style="text-align: center">
			<button type="button" class="layui-btn" id="test1">上传图片</button>
			<section style="    margin-top: 20px;color: #666;">（支持PNG、JPG格式，图片大小1920*750）</section>
			<div class="layui-upload-list">
				<img class="layui-upload-img" id="demo1">
				<p id="demoText"></p>
			</div>
		</div> -->
	</div>
</div>
<script>
	layui.use('upload', function () {
		var $ = layui.jquery
			, upload = layui.upload

		//普通图片上传
		var uploadInst = upload.render({
			elem: '#test1',
			auto: false,
			// multiple: true,
			acceptMime: 'image/png, image/jpeg',
			choose: function (obj) {
				//预读本地文件示例，不支持ie8
				obj.preview(function (index, file) {
					// console.log($('#test1'))
					// initSchedule(1);
					// initSchedule(2);
					// initSchedule(3);
					// var formSelects = layui.formSelects;
					// console.log(formSelects.value('select1', 'val'))
					// var selGrade=[]
					// for(var i=0;i<app.gradeList.length;++i){
					// 	var isCheck = $("#grade"+app.gradeList[i].id).is(":checked")
					// 	if(isCheck){
					// 		selGrade.push(app.gradeList[i].id)
					// 	}
					// }
					// console.log(selGrade)
					applyTokenDo(file, function(ret){
						//dzxh.oss-cn-hangzhou.aliyuncs.com
						var bannerObj={
							imgurl:"https://dzxh.oss-cn-hangzhou.aliyuncs.com/"+ret.name
						}
						varOssImgUrl = 'https://dzxh.oss-cn-hangzhou.aliyuncs.com/' + ret.name
						$('#demo1').show().css('background-image', 'url(' + varOssImgUrl + ')') //图片链接（base64）
						BanneraddObj(bannerObj,function(data){
							layer.alert("增加成功", {
									icon: 6
								},
								function () {
									// 获得frame索引
									var index = parent.layer.getFrameIndex(window.name)
									//关闭当前frame
									parent.layer.close(index)

									// 可以对父窗口进行刷新
									xadmin.father_reload()
								})
						},function(status,message){

						})

					},function(ret){

					});
				})
			},
			error: function () {
				//演示失败状态，并实现重传
				var demoText = $('#demoText')
				demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>')
				demoText.find('.demo-reload').on('click', function () {
					uploadInst.upload()
				})
			}
		})
	})
	// document.getElementById('file-button').onclick = function () {
	//
  //   }
	layui.use(['form', 'layer'],
	function () {
		$ = layui.jquery
		var form = layui.form,
			layer = layui.layer

		//自定义验证规则
		form.verify({
			nikename: function (value) {
				if (value.length < 5) {
					return '昵称至少得5个字符啊'
				}
			},
			pass: [/(.+){6,12}$/, '密码必须6到12位'],
			repass: function (value) {
				if ($('#L_pass').val() != $('#L_repass').val()) {
					return '两次密码不一致'
				}
			}
		})

		//监听提交
		form.on('submit(add)',
			function (data) {
				console.log(data)
				//发异步，把数据提交给php
				layer.alert("增加成功", {
						icon: 6
					},
					function () {
						// 获得frame索引
						var index = parent.layer.getFrameIndex(window.name)
						//关闭当前frame
						parent.layer.close(index)

						// 可以对父窗口进行刷新
						xadmin.father_reload()
					})
				return false
			})

	})
// layui.use('upload', function() {
// 	var $ = layui.jquery
// 		, upload = layui.upload;

// 	//普通图片上传
// 	var uploadInst = upload.render({
// 		elem: '#test1'
// 		, url: '' //改成您自己的上传接口
// 		, before: function (obj) {
// 			//预读本地文件示例，不支持ie8
// 			obj.preview(function (index, file, result) {
// 				$('#demo1').attr('src', result); //图片链接（base64）
// 			});
// 		}
// 		, done: function (res) {
// 			//如果上传失败
// 			if (res.code > 0) {
// 				return layer.msg('上传失败');
// 			}
// 			//上传成功
// 		}
// 		, error: function () {
// 			//演示失败状态，并实现重传
// 			var demoText = $('#demoText');
// 			demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
// 			demoText.find('.demo-reload').on('click', function () {
// 				uploadInst.upload();
// 			});
// 		}
// 	})
// })
</script>
<script>var _hmt = _hmt || [];
(function () {
	var hm = document.createElement("script")
	hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190"
	var s = document.getElementsByTagName("script")[0]
	s.parentNode.insertBefore(hm, s)
})()</script>
</body>

</html>
